tb4dr.age.adjusted.tbl <- svyglm(CERADtotal ~ DietaryLZ + Age, design = NHANES_design)%>%
  tbl_regression(include = c(DietaryLZ),
                 label = list(DietaryLZ ~ 'Age-adjusted'),
                 pvalue_fun = function(x) style_pvalue(x, digits = 2)
  )%>%
  modify_header(
    std.error = "**SE**"
  )
tb4dr.fully.adjusted.tbl <- svyglm(CERADtotal ~ DietaryLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                   design = NHANES_design) %>%
  tbl_regression( include = c(DietaryLZ),
                  label = list(DietaryLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# SupplementLZ
tb4supp.age.adjusted.tbl <- svyglm(CERADtotal ~ SupplementLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
tb4supp.fully.adjusted.tbl <- svyglm(CERADtotal ~ SupplementLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                     design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# Total L.Z gcr
tb4Total.age.adjusted.tbl <- svyglm(CERADtotal ~ TotalLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
tb4Total.fully.adjusted.tbl <- svyglm(CERADtotal ~ TotalLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                      design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# Total L.Z Quartile gcr
tb4Totallz.age.Quartile.adjusted.tbl <- svyglm(CERADtotal ~ TotalLZ.quantile.var + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
tb4Totallz.fully.adjusted.tbl <- svyglm(CERADtotal ~ TotalLZ.quantile.var + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                        design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Fully-adjusted'))
# regression 的结果一般采用纵向拼接（stack）而不是横向拼接（merger）
tb4CERAD.total<-tbl_stack(
  tbls = list(tb4dr.age.adjusted.tbl, tb4dr.fully.adjusted.tbl,
              tb4supp.age.adjusted.tbl, tb4supp.fully.adjusted.tbl,tb4Total.age.adjusted.tbl,tb4Total.fully.adjusted.tbl,tb4Totallz.age.Quartile.adjusted.tbl,tb4Totallz.fully.adjusted.tbl),
  group_header = c("DietaryLZ", "DietaryLZ", "SupplementLZ", "SupplementLZ","TotalLZ", "TotalLZ","Quartile of total L and Z","Quartile of total L and Z"))

# Animal Fluency score
Animaldr.age.adjusted.tbl <- svyglm(AnimalFluency ~ DietaryLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(DietaryLZ),
                 label = list(DietaryLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
Animaldr.fully.adjusted.tbl <- svyglm(AnimalFluency ~ DietaryLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                      design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(DietaryLZ),
                 label = list(DietaryLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# SupplementLZ
Animalsupp.age.adjusted.tbl <- svyglm(AnimalFluency ~ SupplementLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Age-adjusted'))
Animalsupp.fully.adjusted.tbl <- svyglm(AnimalFluency ~ SupplementLZ + Age + Sex + BMXBMI + Alqgroup +
                                          Smokegroup + PIR + educationattainment,
                                        design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )

# Total L.Z gcr
AnimalTotal.age.adjusted.tbl <- svyglm(AnimalFluency ~ TotalLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
AnimalTotal.fully.adjusted.tbl <- svyglm(AnimalFluency ~ TotalLZ + Age + Sex + BMI + Alq.group +
                                           Smoke.group + PIR + Education.attainment,
                                         design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# Total L.Z Quartile gcr
AnimalTotallz1.age.Quartile.adjusted.tbl <- svyglm(AnimalFluency ~ TotalLZ.quantile.var + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
AnimalTotallz1.fully.adjusted.tbl <- svyglm(AnimalFluency ~ TotalLZ.quantile.var + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                            design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# regression 的结果一般采用纵向拼接（stack）而不是横向拼接（merger）
Animal.Fluencytab<-tbl_stack(
  tbls = list(Animaldr.age.adjusted.tbl, Animaldr.fully.adjusted.tbl,
              Animalsupp.age.adjusted.tbl, Animalsupp.fully.adjusted.tbl,AnimalTotal.age.adjusted.tbl,AnimalTotal.fully.adjusted.tbl,AnimalTotallz1.age.Quartile.adjusted.tbl,AnimalTotallz1.fully.adjusted.tbl),
  group_header = c("DietaryLZ", "DietaryLZ", "SupplementLZ", "SupplementLZ","TotalLZ", "TotalLZ","Quartile of total L and Z","Quartile of total L and Z"))


# Digit Symbol Score
#Dietary L and Z
dss.age.adjusted.tbl <- svyglm(DSST ~ DietaryLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(DietaryLZ),
                 label = list(DietaryLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )

dss.fully.adjusted.tbl <- svyglm(DSST ~ DietaryLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                 design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(DietaryLZ),
                 label = list(DietaryLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )

# SupplementLZ
dsssupp2.age.adjusted.tbl <- svyglm(DSST ~ SupplementLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
dsssupp2.fully.adjusted.tbl <- svyglm(DSST ~ SupplementLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                      design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(SupplementLZ),
                 label = list(SupplementLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# Total L.Z gcr
dssTotal2.age.adjusted.tbl <- svyglm(DSST ~ TotalLZ + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
dssTotal2.fully.adjusted.tbl <- svyglm(DSST ~ TotalLZ + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                       design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ),
                 label = list(TotalLZ ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )

# Total L.Z Quartile gcr
dssTotallz2.age.Quartile.adjusted.tbl <- svyglm(DSST ~ TotalLZ.quantile.var + Age, design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Age-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )

dssTotallz2.fully.adjusted.tbl <- svyglm(DSST ~ TotalLZ.quantile.var + Age + Sex + BMXBMI + Alqgroup + Smokegroup + PIR + educationattainment,
                                         design = NHANES_design) %>%
  tbl_regression(exponentiate = TRUE, include = c(TotalLZ.quantile.var),
                 label = list(TotalLZ.quantile.var ~ 'Fully-adjusted'),pvalue_fun = function(x) style_pvalue(x, digits = 2))%>%
  modify_header(
    std.error = "**SE**"
  )
# regression 的结果一般采用纵向拼接（stack）而不是横向拼接（merger）
DSSTcol<-tbl_stack(
  tbls = list(dss.age.adjusted.tbl, dss.fully.adjusted.tbl,
              dsssupp2.age.adjusted.tbl, dsssupp2.fully.adjusted.tbl,dssTotal2.age.adjusted.tbl,dssTotal2.fully.adjusted.tbl,dssTotallz2.age.Quartile.adjusted.tbl,dssTotallz2.fully.adjusted.tbl),
  group_header = c("DietaryLZ", "DietaryLZ", "SupplementLZ", "SupplementLZ","TotalLZ", "TotalLZ","Quartile of total L and Z","Quartile of total L and Z"))
# regression 的结果一般采用纵向拼接（stack）而不是横向拼接（merger）

alllei4<-tbl_merge(tbls = list(tb4CERAD.total,Animal.Fluencytab,DSSTcol),tab_spanner = c('CERAD: Total score','Animal Fluency score','Digit Symbol Score'))
alllei4%>%as_flex_table()%>%flextable::save_as_html(path = "2.8table4.html")